#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
class Solution {
public:
    int lengthOfLongestSubstring(string s) 
    {
        unordered_map<char, int> map;
        int ret = 0, left = 0, n = s.size();
        for (int right = 0; right < n; right++)
        {
            map[s[right]]++;
            while (map[s[right]] > 1) map[s[left++]]--;
            ret = max(ret, right - left + 1);
        }
        return ret;
    }
};
int main() {
    Solution sol;
    string str = "abcabcbb";
    cout << sol.lengthOfLongestSubstring(str) << endl;
    return 0;
}